package org.example.config;

import lombok.extern.slf4j.Slf4j;
import org.example.filter.MyFilter1;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.*;
import java.util.EnumSet;
import java.util.Set;

/**
 * @author 韦兵
 * @since 2025/4/28 14:51
 */
@Slf4j
//public class WebConfig implements WebApplicationInitializer {
public class WebConfig implements ServletContainerInitializer  {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        log.info("is starting...");
        ServletRegistration.Dynamic dispatchServlet = servletContext.addServlet("dispatchServlet", DispatcherServlet.class);
        dispatchServlet.addMapping("/*");
        dispatchServlet.setInitParameter("contextConfigLocation", "classpath:xxx.xml");

        FilterRegistration.Dynamic filter1 = servletContext.addFilter("MyFilter1", MyFilter1.class);
        filter1.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
    }

    /*@Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        log.info("is starting...");
//        servletContext.
//        servletContext.setInitParameter("contextConfigLocation", "classpath:xxx.xml");
        ServletRegistration.Dynamic dispatchServlet = servletContext.addServlet("dispatchServlet", DispatcherServlet.class);
        dispatchServlet.addMapping("/*");
        dispatchServlet.setInitParameter("contextConfigLocation", "classpath:xxx.xml");
        FilterRegistration.Dynamic filter1 = servletContext.addFilter("filter1", MyFilter1.class);
        filter1.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
    }*/
}
